/* =============================================================
 * System Name：Document Control System
 * File Name： UserAction.java
 * --------------------------------------------------------------
 * (C) Copyright M+W Group 2012 All Rights Reserved.
 *
 *  VERSION    DATE        BY                CHANGE/COMMENT
 * ----------------------------------------------------------------
 *
 */
package com.deco.action;

import java.util.Map;

import com.deco.authorization.api.OAuthDelegator;
import com.deco.authorization.user.OAuthUser;
import com.opensymphony.webwork.interceptor.ParameterAware;
import com.opensymphony.webwork.interceptor.SessionAware;
import com.opensymphony.xwork.ActionSupport;

public class UserAction extends ActionSupport implements ParameterAware,
		SessionAware {

	// OAuth Provider, eg. weibo, QQ etc.
	private String provider;
	private OAuthDelegator delegator;
	private String oAuthURL;

	// request parameters
	private Map parameters;
	private Map session;

	// FIXME: Dammy implemation, write out the uid etc. replace with your own
	// logic.
	OAuthUser user;

	public String doOAuthLogin() throws Exception {
		oAuthURL = delegator.auth(provider, session);
		return SUCCESS;
	}

	// FIXME: Dammy implemation, write out the uid etc. replace with your own
	// logic.
	public String doOAuthLoginSuccess() throws Exception {
		user = delegator.callback(parameters, provider, session);
		// TODO: your logic to bind the oauth user to your local user system.
		// For example, if not exist then create it and bind it. If already
		// bind, obtain from your local user system etc.

		return "oauthLoginSuccess";
	}

	public String doCallback() throws Exception {
		return null;
	}

	public void setProvider(String provider) {
		this.provider = provider;
	}

	public void setDelegator(OAuthDelegator delegator) {
		this.delegator = delegator;
	}

	public String getoAuthURL() {
		return oAuthURL;
	}

	public void setParameters(Map parameters) {
		this.parameters = parameters;
	}

	public void setSession(Map session) {
		this.session = session;
	}

	public OAuthUser getUser() {
		return user;
	}

}
